//
//  UILabel+Extension.swift
//  GangHood
//
//  Created by shengjie on 2021/6/3.
//

import Foundation
import UIKit

/*
 * Name: UILabel+Extension
 * Description: UILabel相关处理
 */
extension UILabel {
//    /// laber 适应其宽度
//    func fitToWidth(extraSpace: CGFloat = 0) {
//        width = ((text ?? "") as NSString).width(for: font) + extraSpace
//    }
//    /// laber 适应其高度
//    func fitToHeight(extraSpace: CGFloat = 0) {
//        height = ((text ?? "") as NSString).height(for: font, width: width) + extraSpace
//    }
//
//    /// 计算laber 当前文字宽度
//    func laberWidth() -> CGFloat {
//        return ((text ?? "") as NSString).width(for: font)
//    }
//
//    /// 计算laber 当前文字高度
//    func laberHeight() -> CGFloat {
//        return ((text ?? "") as NSString).height(for: font, width: width)
//    }
    
    /// 设置部分字体的颜色
    func special(text: String , color : UIColor){
        
        guard let range = (self.text as? NSString)?.range(of: text) else {
            return
        }
        if range.location != NSNotFound {
            let attributeString = NSMutableAttributedString(string: self.text!)
            attributeString.addAttribute(NSAttributedString.Key.foregroundColor, value: color, range: range)
            attributedText = attributeString
        }
    }

}
